package com.blrs.controller;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.blrs.common.core.page.PageDomain;
import com.blrs.common.core.page.TableSupport;
import com.blrs.common.utils.SecurityUtils;
import com.blrs.common.utils.page.PaginationUtil;
import com.blrs.domain.vo.EnterpriseVO;
import com.blrs.domain.vo.FeedBackVo;
import com.blrs.service.poliy.IPolicyReleaseService;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.blrs.common.annotation.Log;
import com.blrs.common.core.controller.BaseController;
import com.blrs.common.core.domain.AjaxResult;
import com.blrs.common.enums.BusinessType;
import com.blrs.domain.PolicyRelease;
import com.blrs.common.utils.poi.ExcelUtil;
import com.blrs.common.core.page.TableDataInfo;
import org.springframework.web.client.RestTemplate;

/**
 * 政策发布Controller
 * 
 * @author ruoyi
 * @date 2024-01-09
 */
@RestController
@RequestMapping("/policy/release")
public class PolicyReleaseController extends BaseController
{
    @Autowired
    private IPolicyReleaseService policyReleaseService;


    /**
     * 查询政策发布列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PolicyRelease policyRelease)
    {
        startPage();
        List<PolicyRelease> list = policyReleaseService.selectPolicyReleaseList(policyRelease);
        return getDataTable(list);
    }

    /**
     * 导出政策发布列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, PolicyRelease policyRelease)
    {
        List<PolicyRelease> list = policyReleaseService.selectPolicyReleaseList(policyRelease);
        ExcelUtil<PolicyRelease> util = new ExcelUtil<PolicyRelease>(PolicyRelease.class);
        util.exportExcel(response, list, "政策发布数据");
    }

    /**
     * 获取政策发布详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(policyReleaseService.selectPolicyReleaseByPermissionId(id));
    }

    /**
     * 新增政策发布
     */
    @PostMapping
    public AjaxResult add(@RequestBody PolicyRelease policyRelease) throws NoSuchFieldException, IllegalAccessException {
        return toAjax(policyReleaseService.insertPolicyRelease(policyRelease));
    }

    /**
     * 修改政策发布
     */
    @PutMapping
    public AjaxResult edit(@RequestBody PolicyRelease policyRelease)
    {
        return toAjax(policyReleaseService.updatePolicyRelease(policyRelease));
    }

    /**
     * 删除政策发布
     */
	@DeleteMapping("/{permissionIds}")
    public AjaxResult remove(@PathVariable String[] permissionIds)
    {
        return toAjax(policyReleaseService.deletePolicyReleaseByPermissionIds(permissionIds));
    }
    /**
     * 查看待政策发布列表
     */
    @GetMapping("/Audit")
    public TableDataInfo AuditList(PolicyRelease policyRelease)
    {
        startPage();
        List<PolicyRelease> list = policyReleaseService.selectPolicyReleaseListByExamine(policyRelease);
        return getDataTable(list);
    }

    /**
     * 审核政策发布信息
     */
    @PostMapping("/examine")
    public AjaxResult examinePolicy(@RequestBody PolicyRelease policyRelease){
        return toAjax(policyReleaseService.examinePolicy(policyRelease));
    }

    /**
     * 接收方查看政策发布信息列表
     */
    @GetMapping("/receive")
    public TableDataInfo receiveList(PolicyRelease policyRelease)
    {
        startPage();
        List<PolicyRelease> list = policyReleaseService.selectPolicyReleaseListByReceive(policyRelease);
        return getDataTable(list);
    }
    /**
     * 一键发送终止审核
     */
    @PostMapping("/termination")
    public AjaxResult termination(@RequestBody PolicyRelease policyRelease){
        return toAjax(policyReleaseService.terminationPolicy(policyRelease));
    }
    /**
     * 增加已读标记
     */
    @GetMapping("/read/{id}")
    public AjaxResult read(@PathVariable("id") String id){
        return toAjax(policyReleaseService.read(id, SecurityUtils.getOrgId()));
    }

    /**
     * 添加反馈内容
     */
    @GetMapping("/feedback/{id}")
    public AjaxResult feedback(@PathVariable("id") String id){
        FeedBackVo feedBackVo1 = new FeedBackVo();
        feedBackVo1.setFeedback(SecurityUtils.getOrgName());
        feedBackVo1.setReceiverId(SecurityUtils.getOrgId());
        feedBackVo1.setId(id);
        return toAjax(policyReleaseService.feedback(feedBackVo1));
    }

    /**
     * 获取反馈的企业
     */
    @GetMapping("/enterprise")
    public TableDataInfo enterprise(PolicyRelease policyRelease){
        startPage();
        List<EnterpriseVO> enterpriseVOS = policyReleaseService.selectEnterprise(policyRelease.getId());
        return getDataTable(enterpriseVOS);
    }








}
